<?php
require_once realpath(dirname(__FILE__) . '//..//pages.php');
require_once INC_FUNCTIONS;

authorize ();

if (!isset ($table) && !isset ($result)) {
    notify ('No data to load!');
}

$db = openConnection ();
$fields = $db->getFields ($table);

echo doctype ();
?>
<html>
    <?php echo head (PAGE_TITLE, array (HTTP_CSS_TABLE, HTTP_CSS_MENU)); ?>
    <body>
        <?php
        require_once VW_MENU;
        ?>
        <div class="message" id="table">
            <table>
                <?php foreach ($fields as $field) : ?>
                    <th>
                        <a><?php echo $field->name; ?></a>
                    </th>
                <?php endforeach; ?>
                <?php while ($row = $db->fetchAssoc ($result)) : ?>
                    <tr>
                        <?php foreach ($row as $value) : ?>
                            <td><?php echo $value; ?></td>
                        <?php endforeach; ?>
                        <td id="request"><a href="<?php echo HTTP_CTRL_MAIN . '?ID=' . $row['ID'] . "&request=delete&table=$table"; ?>">Elimina</a></td>
                        <td id="request"><a href="<?php echo HTTP_CTRL_MAIN . '?ID=' . $row['ID'] . "&request=edit&table=$table"; ?>">Modifica</a></td>
                        <td id="request"><a href="<?php echo HTTP_CTRL_MAIN . "?&request=insert&table=$table"; ?>">Nuovo</a></td>
                    </tr>
                <? endwhile; ?>
            </table>
        </div>
    </body>
</html>
